package Polymorphic;

import java.util.Scanner;

/**
 * 学生管理程序的界面
 */
public class StudentUI {
    private SuperArray ary = new SuperArray();
    private Scanner sc = new Scanner(System.in);

    public StudentUI() {
        ary.add(new Student("tom", "男", 20));
        ary.add(new Student("蜘蛛侠", "男", 25));
        ary.add(new Student("喜羊羊", "男", 30));
        ary.add(new Student("佩奇", "男", 30));
        ary.add(new Student("乔治", "男", 30));
        menu();
    }

    /**
     * 菜单界面
     */
    public void menu() {
        System.out.println("欢迎使用学生管理程序");
        while (true) {
            System.out.println("请选择：1-查看所有学生 2-增加 3-修改 4-删除 5-退出");
            int input = sc.nextInt();
            if (input == 1) {
                show();
            } else if (input == 2) {
                add();
            } else if (input == 3) {
                update();
            } else if (input == 4) {
                remove();
            } else if (input == 5) {
                System.out.println("准备退出");
                System.exit(0);
            }
        }
    }

    /**
     * 显示所有学生
     */
    public void show() {
        for (int i = 0; i < ary.size(); i++) {
            Student student = (Student) ary.get(i);
            System.out.println(student.getName() + "," + student.getGender() + "," + student.getAge());
        }
    }

    /**
     * 增加学生
     */

    public void add() {
        System.out.println("请输入学生" + "姓名" + "性别" + "年龄");
        System.out.println("姓名");
        String name = sc.next();
        System.out.println("性别");
        String denger = sc.next();
        System.out.println("年龄");
        int age = sc.nextInt();

        Student student1 = new Student();
        student1.setName(name);
        student1.setGender(denger);
        student1.setAge(age);
        ary.add(student1);
        System.out.println("添加成功");
        System.out.println(student1.getName() + "," + student1.getGender() + "," + student1.getAge());

    }

    /**
     * 修改学生
     */
    public void update() {

        System.out.println("请输入姓名");
        String name = sc.next();
        System.out.println("请输入性别");
        String denger = sc.next();
        System.out.println("请输入年龄");
        int age = sc.nextInt();
        for (int i = 0; i < ary.size(); i++) {
            Student student = (Student) ary.get(i);
            if (name.equals(student.getName())) {
                System.out.println("请选择修改的内容1,姓名 2,性别 3,年龄");
                int a = sc.nextInt();
                if (a == 1) {
                    System.out.println("请输入修改的姓名");
                    String name1 = sc.next();
                    student.setName(name1);
                    System.out.println("姓名修改成功");
                } else if (a == 2) {
                    System.out.println("请输入修改的性别");
                    String denger1 = sc.next();
                    student.setGender(denger1);
                    System.out.println("性别修改成功");
                }
                if (a == 3) {
                    System.out.println("请输入修改的年龄");
                    int age1 = sc.nextInt();
                    student.setAge(age1);
                    System.out.println("年龄修改成功");
                }

            }
            System.out.println("对不起没有找到"+name);
        }
    }

    /**
     * 删除学生
     */
    public void remove() {
        System.out.println("请输入要删除的同学");
        String name = sc.next();
            for (int i = 0; i < ary.size(); i++) {
                Student student = (Student) ary.get(i);
                if (name.equals(student.getName())) {
                    ary.remove(name,);
                    System.out.println("删除成功");
                }
            }
        System.out.println("对不起没有找到"+name);

    }

    public static void main(String[] args) {
        new StudentUI();
    }
}